<template>
  <div class="app-container">
    <el-card>
      <div slot="header" class="clearfix">
        <span>抽奖记录</span>
      </div>

      <div class="filter-container">
        <el-input v-model="listQuery.user" :placeholder="'请输入用户信息'" clearable style="width: 200px;margin-right: 10px;" class="filter-item" @keyup.enter.native="handleFilter" />
    
        <el-select v-model="listQuery.prize_id" style="margin-right: 10px;" clearable placeholder="奖品">
            <el-option v-for="item in prize " :key="item.id" :value="item.id" :label="item.name"></el-option>
        </el-select>
        <el-select v-model="listQuery.status" style="margin-right: 10px;" placeholder="是否领取">
            <el-option label="未领取" :value="0"></el-option>
            <el-option label="已领取" :value="1"></el-option>
        </el-select>

        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
          {{ '搜索' }}
        </el-button>
        <el-button v-waves :disabled="!checkPermission(['prize.prize_log_export'])"  type="success" icon="el-icon-upload2" @click="handleExport">
            {{ '导出' }}
        </el-button>
      </div>

      <el-table
        v-loading="listLoading"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%"
        row-key="id"
        :tree-props="{children: 'children'}"
      >

        <el-table-column width="100" label='编号'>
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column  label='用户'  align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.nickname }}</span>
          </template>
        </el-table-column>
        <el-table-column  label='奖品类型' align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.type_text}}</span>
          </template>
        </el-table-column>
         <el-table-column  label='奖品名称' align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.prize_name}}</span>
          </template>
        </el-table-column>
         <el-table-column  label='留资姓名' align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.name}}</span>
          </template>
        </el-table-column>
         <el-table-column  label='留资姓名' align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.mobile}}</span>
          </template>
        </el-table-column>
         <el-table-column  label='领取状态' align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.status_text}}</span>
          </template>
        </el-table-column>
        <el-table-column  label='中奖时间' align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.log_time}}</span>
          </template>
        </el-table-column>
    

      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </el-card>
  </div>
</template>

<script>
import {export_excell} from '@/api/export_excell' // 导出
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import permission from '@/directive/permission/index.js' // 权限判断指令
import checkPermission from '@/utils/permission' // 权限判断函数
import { prize_log } from '@/api/prize'
import { parseTime } from '@/utils'
export default {
  name: 'question_record',
  components: { Pagination },
  directives: { waves, permission },
  filters: {
    parseTime
  },
  data() {
    return {
      list: [],
      prize : [],
      total: 0,
      select_ids:[],
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
     handleExport(){
        //导出
        let query="";
      for ( let key in this.listQuery) {
          query+= `${key}=${this.listQuery[key]}&`
      }
      window.location.href = process.env.VUE_APP_BASE_API + `admin/prize_log_export?${query}`;
      },
    checkPermission,
    getList() {
      this.listLoading = true
      prize_log(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.prize = response.data.prize
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleCreate() {
      this.create.dialogVisible = true
    },
    handleEdit(index, row) {
      this.edit.dialogVisible = true
      this.edit.id = row.id
    },
    handleDownload(){
      location.href = 'https://game.vrupup.com/resources/sam_base/answer.csv';
    },
    handleBatch() {
        var that = this;
        if(this.select_ids.length == 0){
            this.$message({
                message: '请选择要删除的信息',
                type: 'warning'
            });
            return false;
        }
        this.$confirm('确认删除选中的用户?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            del(this.select_ids.join(',')).then(res => {
                this.$message({
                    message: '删除成功',
                    type: 'success'
                });
                this.getList();
            }).catch(err => {
                this.$message({
                    message: err.msg,
                    type: 'error'
                });
            })
        }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消删除'
            });
        });
    },
    handleDelete(index, row) {
      const thiz = this
      this.$confirm('确认要删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del(row.id).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success',
            duration: 1500,
            onClose() {
              thiz.list.splice(index, 1)
            }
          })
        })
      }).catch(() => {

      })
    }
  }
}
</script>

<style scoped>
.pagination-container {
  padding: 5px 2px;
}
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
